<template>
	<view>
		<view class="padding  bg-white">
			<view class="text-bold">
				金币总数：{{totalCoinNum}}
			</view>
			<view class="margin-top-sm text-gray text-sm">
				1个金币相当于1元人民币
			</view>
			<view class="margin-top">
				<form class="margin-top">
					<view class="cu-form-group">
						<view class="title"><text class="text-red">*</text>账号类型</view>
						<picker @change="typeChange" :range="types" range-key="label">
							<view class="picker"> {{selType}} </view>
						</picker>
					</view>
					<view class="cu-form-group">
						<view class="title"><text class="text-red">*</text>账号信息</view>
						<input placeholder="支付宝账号或微信号" v-model="transfer.account" class="text-right" name="input"></input>
					</view>
					<view class="cu-form-group">
						<view class="title"><text class="text-red">*</text>收款人姓名</view>
						<input placeholder="请输入收款人真实姓名" v-model="transfer.accountName" class="text-right" name="input"></input>
					</view>
					<view class="cu-form-group">
						<view class="title"><text class="text-red">*</text>提现金额</view>
						<picker @change="cashChange" :range="cashList">
							<view class="picker"> {{transfer.goldCoinNum}} </view>
						</picker>
					</view>
				</form>
			</view>

			<view class="text-center margin-top">
				<button :disabled="!transfer.account || !transfer.accountName" style="width: 100%;" class="cu-btn padding-lg  bg-green" @tap="crash">确认提现</button>
			</view>
			<view class="margin-top padding text-gray">
				提现金额会在提现三个工作日内打到您的账号，请确保账号信息准确。
				<!-- <view class="padding-top-xs">
					如有疑问可联系客服
					<text @tap="phoneCall" class="padding-left-xs text-blue">{{phone}}</text>
				</view> -->
			</view>
		</view>
		
		<view class="cu-modal" :class="showModal?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">提示</view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding-xl">
					请在每月的15号和28号提现。
				</view>
			</view>
		</view>
		
		<view class="cu-modal" :class="showModal2?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">提示</view>
					<view class="action" @tap="showModal2 = false">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding-xl">
					提现成功，我们会在三个工作日内将钱打到您所填写的账户中，请注意查收。
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showModal: false,
				showModal2: false,
				cashList: [15, 30, 60, 90],
				selType: '支付宝',
				types: [{
					label: '支付宝', value: '1'
				}, {
					label: '微信', value: '0'
				}],
				phone: '',
				transfer: {
					account: '',
					accountName: '',
					accountType: '1',
					goldCoinNum: '15',
					transferRemake: '',
				},
				totalCoinNum: 0
			};
		},
		onLoad(options) {
			/*
			let day = new Date().getDate();
			if(day != 15 && day != 28){
				// 提示信息，不可提现
				this.showModal = true;
				return;
			}
			*/
			
			if (options.currentCreditNum) {
				this.totalCoinNum = options.currentCreditNum ? parseInt(options.currentCreditNum) : 0;
			}
		},
		methods: {
			hideModal(){
				uni.navigateBack({
					
				})
			},
			typeChange(e){
				let index = e.detail.value;
				this.selType = this.types[index].label;
				this.transfer.accountType = this.types[index].value;
			},
			cashChange(e){
				let index = e.detail.value;
				this.transfer.goldCoinNum = this.cashList[index];
			},
			// 
			phoneCall() {
				let phone = this.phone;
				uni.makePhoneCall({
					phoneNumber: phone
				})
			},
			crash() {
				let _this = this;
				uni.showModal({
					content: '请确保您的账号信息准确!',
					confirmText: '确定提交',
					success(res) {
						if (res.confirm) {
							if(_this.transfer.goldCoinNum > _this.totalCoinNum){
								uni.showToast({
									title: '提现金额不能大于金币总数',
									icon: 'none'
								})
								return;
							}
							_this.baseRequest('api/transfer/crash', 'POST', _this.transfer, function(res){
								_this.showModal2 = true;
								_this.totalCoinNum -= _this.transfer.goldCoinNum;
							});
						}
					}
				});
			},
		}
	}
</script>

<style>

</style>
